package com.tdam.CommunicationManager;

import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

import android.provider.CallLog;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class LogInfoHolder extends Holder
{
	private TextView txtContactName;
	private TextView txtLogDate;
	private TextView txtNumber;
	private ImageView imgType;
	private ImageView imgEdit;

	
	
	
	@Override
	void fill(Object item) 
	{
		txtContactName.setText(((LogInfo)item).contactName);
		txtNumber.setText(((LogInfo)item).number);
		Date logDate=((LogInfo)item).date;
		Date today=new Date();
		today.setHours(0);
		today.setMinutes(0);
		today.setSeconds(0);
		long diff=logDate.getTime()-today.getTime();
		SimpleDateFormat formatter=new SimpleDateFormat("dd/MM/yy HH:mm");
		
		if(diff>=0)
		{
			formatter.applyPattern("HH:mm");
			txtLogDate.setText("Hoy " + formatter.format(logDate));
		}
		else
			txtLogDate.setText(formatter.format(logDate));
		
		switch(((LogInfo)item).type)
		{
		case LogInfo.INCOMING:
			imgType.setImageResource(R.drawable.incoming_call);
			break;
		case LogInfo.OUTGOING:
			imgType.setImageResource(R.drawable.outgoing_call);
			break;
		case LogInfo.MISSED:
			imgType.setImageResource(R.drawable.not_answered_call);
			break;	
		case LogInfo.SMS_RECEIVED:
			imgType.setImageResource(R.drawable.receive_sms);
			break;
		case LogInfo.SMS_SEND:
			imgType.setImageResource(R.drawable.send_sms);
			break;
		}
		switch(((LogInfo)item).edit)
		{
			case NOT_EDIT:
				imgEdit.setVisibility(View.GONE);
				break;
			case EDIT_MARKED:
				imgEdit.setImageResource(R.drawable.delete_down);
				imgEdit.setVisibility(View.VISIBLE);
				break;
			case EDIT_NOT_MARKED:
				imgEdit.setImageResource(R.drawable.delete_up);
				imgEdit.setVisibility(View.VISIBLE);
				break;
		}
		
	}

	@Override
	void link(View convertView) 
	{
		txtContactName=(TextView) convertView.findViewById(R.id.txtContactName);
		txtLogDate=(TextView) convertView.findViewById(R.id.txtLogDate);
		txtNumber=(TextView) convertView.findViewById(R.id.txtNumber);
		imgType=(ImageView) convertView.findViewById(R.id.imgType);
		imgEdit=(ImageView) convertView.findViewById(R.id.imgEdit);
	}
	


}
